package com.warrior.gatherclient.service.impl;

import com.warrior.gatherclient.grpc.GpcResponse;
import com.warrior.gatherclient.grpc.MessageServiceGrpc;
import com.warrior.gatherclient.grpc.Messages;
import io.grpc.Channel;
import net.devh.boot.grpc.client.inject.GrpcClient;
import org.springframework.stereotype.Service;

/**
 * @ClassName com.warrior.gatherclient.service.GrpcClientService.java
 * @Author xujian
 * @Description
 * @CreateTime 2020年12月21日 15:20:00
 */
@Service
public class GrpcClientService {

    @GrpcClient("grpc-server")
    private Channel serverChannel;

    public GpcResponse sendMessage(Messages.Builder messages) {
        MessageServiceGrpc.MessageServiceBlockingStub stub = MessageServiceGrpc.newBlockingStub(serverChannel);
        GpcResponse gpcResponse = stub.sendMessages(messages.build());
        return gpcResponse;
    }

}
